﻿Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls

Namespace Controls
    ''' <summary> 
    ''' 下拉列表选项转换器 
    ''' </summary> 
    Public Class FormControlsConverter
        Inherits StringConverter
        ''' <summary> 
        ''' 构造函数 
        ''' </summary> 
        Public Sub New()
        End Sub

        ''' <summary> 
        ''' 下拉列表编辑属性 
        ''' </summary> 
        ''' <param name="context"></param> 
        ''' <returns></returns> 
        Public Overloads Overrides Function GetStandardValuesSupported(ByVal context As ITypeDescriptorContext) As Boolean
            Return True
        End Function


        ''' <summary> 
        ''' 获取标准值列表 
        ''' </summary> 
        ''' <param name="context"></param> 
        ''' <returns></returns> 
        Public Overloads Overrides Function GetStandardValues(ByVal context As ITypeDescriptorContext) As System.ComponentModel.TypeConverter.StandardValuesCollection
            Dim Controls As ControlCollection = DirectCast(context.Container.Components(0), Page).Controls
            Dim controlsArray As New ArrayList()
            For i As Integer = 0 To Controls.Count - 1
                If (TypeOf Controls(i) Is HtmlTable OrElse TypeOf Controls(i) Is HtmlForm OrElse TypeOf Controls(i) Is HtmlGenericControl OrElse TypeOf Controls(i) Is HtmlImage OrElse TypeOf Controls(i) Is Label OrElse TypeOf Controls(i) Is DataGrid OrElse TypeOf Controls(i) Is DataList OrElse TypeOf Controls(i) Is Table OrElse TypeOf Controls(i) Is Repeater OrElse TypeOf Controls(i) Is Image OrElse TypeOf Controls(i) Is Panel OrElse TypeOf Controls(i) Is PlaceHolder OrElse TypeOf Controls(i) Is Calendar OrElse TypeOf Controls(i) Is AdRotator OrElse TypeOf Controls(i) Is Xml) Then
                    controlsArray.Add(Controls(i).ClientID)
                End If
            Next
            Return New StandardValuesCollection(controlsArray)

        End Function

        ''' <summary> 
        ''' return ture的话只能选,return flase可选可填 
        ''' </summary> 
        ''' <param name="context"></param> 
        ''' <returns></returns> 
        Public Overloads Overrides Function GetStandardValuesExclusive(ByVal context As ITypeDescriptorContext) As Boolean
            Return False
        End Function
    End Class
End Namespace